#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ls (x << 1)
#define rs (x << 1 | 1)
using namespace std;

const int N = 5e5 + 10, INF = 0x3f3f3f3f;

int n, m;
char s[N];
struct node {
    int l, r, pre, suf, mx;
    char prech, sufch;
    int len() { return r - l + 1; }
}t[N << 4];

void pushup(int x)
{
    t[x].pre = t[ls].pre; t[x].prech = t[ls].prech;
    t[x].suf = t[rs].suf; t[x].sufch = t[rs].sufch;

    if (t[ls].pre == t[ls].len() && t[ls].prech == t[rs].prech) t[x].pre += t[rs].pre;
    if (t[rs].suf == t[rs].len() && t[rs].sufch == t[ls].sufch) t[x].suf += t[ls].suf;

    t[x].mx = max(t[ls].mx, t[rs].mx);
    if (t[ls].sufch == t[rs].prech) t[x].mx = max(t[x].mx, t[ls].suf + t[rs].pre);
}

void build(int x, int l, int r)
{
    t[x].l = l;t[x].r = r;
    if (l == r) {
        t[x].prech = t[x].sufch = s[l];
        t[x].pre = t[x].suf = t[x].mx = 1;
        return;
    }
    int mid = (l + r) >> 1;
    build(ls, l, mid);build(rs, mid + 1, r);
    pushup(x);
}

void modify(int x, int id, char ch)
{
    if (t[x].l == t[x].r && t[x].l == id) {
        t[x].prech = t[x].sufch = ch;
        return;
    }
    int mid = (t[x].l + t[x].r) >> 1;
    if (id <= mid) modify(ls, id, ch);
    else modify(rs, id, ch);
    pushup(x);
}

node merge(node a, node b)
{
    node res;
    res.pre = a.pre; res.prech = a.prech;
    res.suf = b.suf; res.sufch = b.sufch;

    if (a.pre == a.len() && a.prech == b.prech) res.pre += b.pre;
    if (b.suf == b.len() && b.sufch == a.sufch) res.suf += a.suf;

    res.mx = max(a.mx, b.mx);
    if (a.sufch == b.prech) res.mx = max(res.mx, a.suf + b.pre);
    return res;
}

node query(int x, int l, int r)
{
    if (l <= t[x].l && t[x].r <= r) return t[x];
    int mid = (t[x].l + t[x].r) >> 1;
    if (r <= mid) return query(ls, l, r);
    if (l > mid) return query(rs, l, r);
    return merge(query(ls, l, r), query(rs, l, r));
}

inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch>'9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(x % 10 + '0');
    return;
}

void solve()
{
    n = read(), m = read();
    scanf("%s", s + 1);
    build(1, 1, n);

    int op, l, r;
    char ch;
    while (m--) {
        op = read();
        if (op == 1) {
            l = read();
            ch = getchar();
            modify(1, l, ch);
        } else {
            l = read(), r = read();
            cout << query(1, l, r).mx << '\n';
        }
    }
}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}